package com.jinyang.jetpackdemo.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.jinyang.jetpackdemo.R
import com.jinyang.jetpackdemo.activity.ClassLoaderActivity
import com.jinyang.jetpackdemo.factorial
import com.jinyang.jetpackdemo.fib

class ClassLoaderActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_class_loader)
        println("boot.class.path: " + System.getProperty("sun.boot.class.path"))
        println("java.ext.dirs: " + System.getProperty("java.ext.dirs"))
        var loader: ClassLoader? = MyClassLoader()
        while (loader != null) {
            println("loader:$loader")
            loader = loader.parent
        }
        val classLoader1 = MyClassLoader()
        val classLoader2 = MyClassLoader2()
        try {
            println(
                "ClassLoaderTest1:" + classLoader1.loadClass(ClassLoaderActivity::class.java.name)
                    .hashCode()
            )
            println(
                "ClassLoaderTest2:" + classLoader2.loadClass(ClassLoaderActivity::class.java.name)
                    .hashCode()
            )
        } catch (e: ClassNotFoundException) {
            println("ClassNotFoundException:" + e.localizedMessage)
        }

        log(fib(10)) // 55

        log(factorial(10)) // 3628800

    }

    class MyClassLoader : ClassLoader()
    class MyClassLoader2 : ClassLoader()
}